function show_action_count(anchor, user, date) {
    var span =$(anchor).parents('span.action-count');
    $(anchor).parents('span.action-count').html('loading...');

    $(span).load('index.php?op=action-count',
                 {user: user, date: date});
}

function condition_by() {
    var base_url = 'index.php';

    var orderby = $('select[name="orderby"]').val();
    var limit = parseInt($('select[name="limit"]').val()) + 1;
    window.location = sprintf("index.php?orderby=%s&limit=%s",
                              orderby, limit);
}

function show_pwd(id) {
    $("#"+id).show();
}

function hide_pwd(id) {
    $("#"+id).hide();
}

$(document).ready(function() {
    $("a.delete_account").click(function() {
        var email = $(this).attr('email');
        var nick = $(this).parent().find('a:eq(1)').text();
        var cur_line = $(this).parents('tr');
        if (confirm(sprintf('删除昵称为(%s)的ID\n其邮箱是(%s)\n你确定吗?',
                            nick, email))) {
            $(cur_line).css('text-decoration: blink');

            $.ajax({
                url: 'remove_id.php',
                type: 'GET',
                async: false,
                data: {'email': email,
                       'nick': nick},
                success: function(data) {
                    alert(data);
                    var count = 0;
                    found = false;
                    while (!found && count < 15 && cur_line != undefined) {
                        count++;
                        if ($(cur_line).hasClass('delim')) {
                            found = true;
                        }
                        var target = cur_line;
                        cur_line = $(cur_line).next();
                        $(target).remove();
                    }
                    if (count == 15) {
                        alert('已经删除但调整网页失败');
                    }
                },
                error: function() {
                    alert('删除失败');
                }
            });
        }

    });

    // check follower sum number
    var follower_count = 0;
    $("tr.first-row td.follow-td").each(function(index, elem) {
        follower_count += parseInt($(elem).find("span:first").text());
    });
    $("div.left_data").append("<hr />check by JS: " + follower_count);
});

